<template>
  <div>
    <TopFilter :list="topFilterList" :cols="3" @filterChange="changeHandle"></TopFilter>
    <FilterTable
      ref="table"
      height="240"
      :columns="columns"
      :fetchapi="fetchApi"
      :params="fetchParams"
      :datakey="'records'"
      :uidkey="'customersNo'"
      :selectionType="'single'"
      :onRowSelectChange="selectChangeHandle"
      :onColumnsChange="(columns) => (this.columns = columns)"
    >
    </FilterTable>
    <div
      :style="{
        position: 'absolute',
        left: 0,
        bottom: 0,
        right: 0,
        zIndex: 9,
        borderTop: '1px solid #e9e9e9',
        padding: '10px 20px',
        background: '#fff',
        textAlign: 'right',
      }"
    >
      <el-button @click="closeDrawer(1)">关 闭</el-button>
      <el-button @click="closeDrawer(2)" type="primary" :disabled="selectRow.length < 1">确 定</el-button>
    </div>
  </div>
</template>
<script>
import { getQueryList, getCustomerDetail } from '@/api/omSaleP/KeyCustomers/OrderSubmission/index.js';
import { dictionary } from '@/utils/dictMixin';
import { arrayObjDeWeight } from '@/utils'; //数组去重

export default {
  data() {
    return {
      topFilterList: this.createdFrom(),
      columns: this.createdTable(),
      fetchParams: { isDealer: 10041002, status: 21461003 },
      fetchApi: getQueryList,
      selectRow: [], // 选中行
    };
  },
  mounted() {
    // this.tables = this.$refs.tables.$refs.pageTable;
  },
  mixins: [dictionary],
  methods: {
    // 选中行操作
    selectChangeHandle(e) {
      this.selectRow = e;
    },
    changeHandle(val) {
      this.fetchParams = Object.assign({}, this.fetchParams, val);
    },
    async closeDrawer(type) {
      if (type == 1) {
        this.$emit('close');
      } else {
        let selectData = this.selectRow[0];
        let res = await getCustomerDetail({ bigCustomerId: selectData.id });
        let customerData = res.data;
        if (res.resultCode === 200) {
          if (customerData.isBind !== 10041001) {
            this.$notify({
              title: '警告',
              message: '请在[大客户报备]菜单绑定SAP客户编号后绑定SAP后再进行大客户订单操作',
              type: 'warning',
            });
          } else {
            this.$emit('close', false, res.data);
          }
        }
      }
    },
    createdFrom() {
      return [
        {
          type: 'INPUT',
          label: '大客户编号',
          fieldName: 'customersNo',
          placeholder: '请选择',
        },
        {
          type: 'INPUT',
          label: '大客户名称',
          fieldName: 'customersName',
          placeholder: '请选择',
        },
      ];
    },
    createdTable() {
      return [
        {
          title: '序号',
          dataIndex: 'index',
          width: 80,
          sorter: true,
          fixed: 'left',
          render: (props) => {
            return <span>{props.row.index + 1}</span>;
          },
        },
        {
          title: '大客户编号',
          dataIndex: 'customersNo',
          sorter: true,
          filter: true,
          filterType: 'input',
          width: 200,
        },
        {
          title: '大客户名称',
          dataIndex: 'customersName',
          sorter: true,
          filter: true,
          filterType: 'input',
          width: 200,
        },
        {
          title: '运营单位联系人',
          dataIndex: 'contactsName',
          sorter: true,
          filter: true,
          filterType: 'input',
        },
        {
          title: '运营单位联系电话',
          dataIndex: 'customerPhone',
          sorter: true,
          filter: true,
          filterType: 'input',
        },
        {
          title: '联系地址',
          dataIndex: 'addressName',
          sorter: true,
          filter: true,
          filterType: 'input',
        },
        {
          title: '提报人',
          dataIndex: 'reportPersonName',
          sorter: true,
          filter: true,
          filterType: 'input',
        },
        {
          title: '提报时间',
          dataIndex: 'reportDate',
          sorter: true,
          filter: true,
          filterType: 'input',
          dateFormat: 'yyyy-MM-dd',
        },
        {
          title: '审核人',
          dataIndex: 'auditName',
          sorter: true,
          filter: true,
          filterType: 'input',
        },
        {
          title: '审核时间',
          dataIndex: 'auditTime',
          sorter: true,
          filter: true,
          filterType: 'input',
          dateFormat: 'yyyy-MM-dd',
        },
      ];
    },
  },
};
</script>
